// import { getSecondGoodsTypeDataByIdData } from "@/apis/goodsType";
import { getGoodsInfoBySecondGoodsTypeIdData } from "@/apis/goodsInfo";
import { useRoute, onBeforeRouteUpdate } from "vue-router";
import { onMounted, ref } from "vue"


export function useGoodsData(pageInfo) {
const route = useRoute();
const goodsData = ref([]);

pageInfo.value.pageGoodsTypeId = route.params.id
const getGoodsDataById = async ( pageInfo ) => {
  const res = await getGoodsInfoBySecondGoodsTypeIdData(pageInfo);
  goodsData.value = res.data;
};
onBeforeRouteUpdate((to) => {
  // 存在问题：使用最新的路由参数请求最新的分类数据
  getGoodsDataById(to.params.id);
});
onMounted(() => {
    getGoodsDataById();
});
    return {
        goodsData
    }
}